import os
import numpy as np


def read_graph(graph_filename):
    assert os.path.exists(graph_filename),"graph file does not exists!"
    with open(graph_filename,"r") as f:
        for line in f.readlines(): 
            line = line.strip("\n")
            if line.startswith("p"):
                words = line.split(" ")
                nodes = int(words[2])
                edges_num = int(words[3])
                graph = np.zeros((nodes,nodes))
            if line.startswith("e"):
                words = line.split(" ")
                nodes_1 = int(words[1])-1
                nodes_2 = int(words[2])-1
                graph[nodes_1,nodes_2] = 1
                graph[nodes_2,nodes_1] = 1
    return graph

if __name__ == "__main__":
    graph = read_graph("graphs/DSJC125.1.col")
    print("edge 19 11 %d" % graph[18,10])
    print("edge 19 12 %d" % graph[18,11])
